In [1]:
import shopify
tool - 1 Remove app
API Key f402c6ff49515572dc9e54a179b17c1e
Password 2d2b63c69ffd14d0e3905b0ed33f3332
Shared Secret 542b6edb1ce5e2850a9c112c1f906272
URL Format https://apikey:password@hostname/admin/resource.xml
Example URL https://f402c6ff49515572dc9e54a179b17c1e:2d2b63c69ffd14d0e3905b0ed33f3332@tomfoolery-3.myshopify.com/admin/orders.xml
In [7]:
SHOP_NAME = "tomfoolery-3"
API_PASSWORD = "2d2b63c69ffd14d0e3905b0ed33f3332"
session = shopify.Session(SHOP_NAME)
session.token = API_PASSWORD
shopify.ShopifyResource.activate_session(session)
In [8]:
products = shopify.Product.find()
In [9]:
products
Out[9]:
In [17]:
products[0].attributes
Out[17]:
In [23]:
i = products[0].images[0]
In [25]:
i.get_id()
Out[25]:
In [29]:
from IPython.core.display import Image
Image(url=products[0].images[0].src)
Out[29]:
In [34]:
#instantiate a new product
new_product = shopify.Product()
print new_product.id # Only exists in memory for now
In [35]:
# add main meta info
new_product.product_type = "punctuation"
new_product.body_html = "<strong>!?!?!</strong>"
new_product.title = "Surprised"
In [36]:
# create product variants
variant1 = shopify.Variant()
variant2 = shopify.Variant(dict(price="20.00", option1="Second")) # attributes can be set at creation
new_product.variants = [variant1, variant2]
In [38]:
new_product.vendor = "Burton"
new_product.save() # Sends request to Shopify
new_product.id
Out[38]:
In [39]:
# or create a product with create
product = shopify.Product.create(dict(product_type="Snowboard", body_html="<strong>Good snowboard!</strong>", title="Burton Custom Freestlye 151", tags="Barnes & Noble, John's Fav, \"Big Air\"", vendor="Burton"))
product.id # The create method already called save
Out[39]:
In [44]:
# Error Handling
bad_product = shopify.Product.create(dict(product_type=''))
bad_product.save()
Out[44]:
In [45]:
bad_product.errors.full_messages()
Out[45]:
In [ ]: